<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  Foreign.Marshal.Utils</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The FFI task force 2001</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  ffi@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Utilities for primitive marshaling</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Foreign.Marshal.Utils</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-19"></span><span>  </span><span class="annot"><span class="hs-comment">-- * General marshalling utilities</span></span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Combined allocation and marshalling</span></span><span>
</span><span id="line-22"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-23"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#with"><span class="hs-identifier">with</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#new"><span class="hs-identifier">new</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Marshalling of Boolean values (non-zero corresponds to 'True')</span></span><span>
</span><span id="line-27"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-28"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#fromBool"><span class="hs-identifier">fromBool</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#toBool"><span class="hs-identifier">toBool</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>
</span><span id="line-31"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Marshalling of Maybe values</span></span><span>
</span><span id="line-32"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-33"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#maybeNew"><span class="hs-identifier">maybeNew</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#maybeWith"><span class="hs-identifier">maybeWith</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#maybePeek"><span class="hs-identifier">maybePeek</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Marshalling lists of storable objects</span></span><span>
</span><span id="line-38"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-39"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#withMany"><span class="hs-identifier">withMany</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Haskellish interface to memcpy and memmove</span></span><span>
</span><span id="line-42"></span><span>  </span><span class="hs-comment">-- | (argument order: destination, source)</span><span>
</span><span id="line-43"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-44"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier">copyBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#moveBytes"><span class="hs-identifier">moveBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Filling up memory area with required values</span></span><span>
</span><span id="line-48"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-49"></span><span>  </span><span class="annot"><a href="Foreign.Marshal.Utils.html#fillBytes"><span class="hs-identifier">fillBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-50"></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Ptr.html"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>              </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier">Ptr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier">nullPtr</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>         </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier">Storable</span></a></span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Storable.html#poke"><span class="hs-identifier">poke</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Types.html"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>          </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier">CSize</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier">CInt</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html"><span class="hs-identifier">Foreign.Marshal.Alloc</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#malloc"><span class="hs-identifier">malloc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier">alloca</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Word.html"><span class="hs-identifier">Data.Word</span></a></span><span>                </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier">Word8</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>                 </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier">fromIntegral</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-comment">-- combined allocation and marshalling</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- -----------------------------------</span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="hs-comment">-- |Allocate a block of memory and marshal a value into it</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- (the combination of 'malloc' and 'poke').</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- The size of the area allocated is determined by the 'Foreign.Storable.sizeOf'</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- method from the instance of 'Storable' for the appropriate type.</span><span>
</span><span id="line-70"></span><span class="hs-comment">--</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- The memory may be deallocated using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-72"></span><span class="hs-comment">-- 'Foreign.Marshal.Alloc.finalizerFree' when no longer required.</span><span>
</span><span id="line-73"></span><span class="hs-comment">--</span><span>
</span><span id="line-74"></span><span id="local-6989586621679537911"><span class="annot"><a href="Foreign.Marshal.Utils.html#new"><span class="hs-identifier hs-type">new</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537911"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537911"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537911"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-75"></span><span id="new"><span class="annot"><span class="annottext">new :: forall a. Storable a =&gt; a -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Utils.html#new"><span class="hs-identifier hs-var hs-var">new</span></a></span></span><span> </span><span id="local-6989586621679537832"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679537832"><span class="hs-identifier hs-var">val</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span>
</span><span id="line-76"></span><span>  </span><span class="hs-keyword">do</span><span>
</span><span id="line-77"></span><span>    </span><span id="local-6989586621679537831"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537831"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (Ptr a)
forall a. Storable a =&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#malloc"><span class="hs-identifier hs-var">malloc</span></a></span><span>
</span><span id="line-78"></span><span>    </span><span class="annot"><span class="annottext">Ptr a -&gt; a -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#poke"><span class="hs-identifier hs-var">poke</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537831"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679537832"><span class="hs-identifier hs-var">val</span></a></span><span>
</span><span id="line-79"></span><span>    </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537831"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span class="hs-comment">-- |@'with' val f@ executes the computation @f@, passing as argument</span><span>
</span><span id="line-82"></span><span class="hs-comment">-- a pointer to a temporarily allocated block of memory into which</span><span>
</span><span id="line-83"></span><span class="hs-comment">-- @val@ has been marshalled (the combination of 'alloca' and 'poke').</span><span>
</span><span id="line-84"></span><span class="hs-comment">--</span><span>
</span><span id="line-85"></span><span class="hs-comment">-- The memory is freed when @f@ terminates (either normally or via an</span><span>
</span><span id="line-86"></span><span class="hs-comment">-- exception), so the pointer passed to @f@ must /not/ be used after this.</span><span>
</span><span id="line-87"></span><span class="hs-comment">--</span><span>
</span><span id="line-88"></span><span id="local-6989586621679537903"><span id="local-6989586621679537904"><span class="annot"><a href="Foreign.Marshal.Utils.html#with"><span class="hs-identifier hs-type">with</span></a></span><span>       </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537904"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537904"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537904"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537903"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537903"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-89"></span><span id="with"><span class="annot"><span class="annottext">with :: forall a b. Storable a =&gt; a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Utils.html#with"><span class="hs-identifier hs-var hs-var">with</span></a></span></span><span> </span><span id="local-6989586621679537824"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679537824"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span id="local-6989586621679537823"><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537823"><span class="hs-identifier hs-var">f</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span>
</span><span id="line-90"></span><span>  </span><span class="annot"><span class="annottext">(Ptr a -&gt; IO b) -&gt; IO b
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr a -&gt; IO b) -&gt; IO b) -&gt; (Ptr a -&gt; IO b) -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679537822"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537822"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-91"></span><span>    </span><span class="annot"><span class="annottext">Ptr a -&gt; a -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#poke"><span class="hs-identifier hs-var">poke</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537822"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679537824"><span class="hs-identifier hs-var">val</span></a></span><span>
</span><span id="line-92"></span><span>    </span><span id="local-6989586621679537821"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679537821"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537823"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537822"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-93"></span><span>    </span><span class="annot"><span class="annottext">b -&gt; IO b
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679537821"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-94"></span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span class="hs-comment">-- marshalling of Boolean values (non-zero corresponds to 'True')</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- -----------------------------</span><span>
</span><span id="line-98"></span><span>
</span><span id="line-99"></span><span class="hs-comment">-- |Convert a Haskell 'Bool' to its numeric representation</span><span>
</span><span id="line-100"></span><span class="hs-comment">--</span><span>
</span><span id="line-101"></span><span id="local-6989586621679537895"><span class="annot"><a href="Foreign.Marshal.Utils.html#fromBool"><span class="hs-identifier hs-type">fromBool</span></a></span><span>       </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Num.html#Num"><span class="hs-identifier hs-type">Num</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537895"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537895"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-102"></span><span id="fromBool"><span class="annot"><span class="annottext">fromBool :: forall a. Num a =&gt; Bool -&gt; a
</span><a href="Foreign.Marshal.Utils.html#fromBool"><span class="hs-identifier hs-var hs-var">fromBool</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span>
</span><span id="line-103"></span><span class="annot"><a href="Foreign.Marshal.Utils.html#fromBool"><span class="hs-identifier hs-var">fromBool</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">1</span></span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="hs-comment">-- |Convert a Boolean in numeric representation to a Haskell value</span><span>
</span><span id="line-106"></span><span class="hs-comment">--</span><span>
</span><span id="line-107"></span><span id="local-6989586621679537893"><span class="annot"><a href="Foreign.Marshal.Utils.html#toBool"><span class="hs-identifier hs-type">toBool</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-type">Eq</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537893"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Num.html#Num"><span class="hs-identifier hs-type">Num</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537893"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537893"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span>
</span><span id="line-108"></span><span id="toBool"><span class="annot"><span class="annottext">toBool :: forall a. (Eq a, Num a) =&gt; a -&gt; Bool
</span><a href="Foreign.Marshal.Utils.html#toBool"><span class="hs-identifier hs-var hs-var">toBool</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span>
</span><span id="line-111"></span><span class="hs-comment">-- marshalling of Maybe values</span><span>
</span><span id="line-112"></span><span class="hs-comment">-- ---------------------------</span><span>
</span><span id="line-113"></span><span>
</span><span id="line-114"></span><span class="hs-comment">-- |Allocate storage and marshal a storable value wrapped into a 'Maybe'</span><span>
</span><span id="line-115"></span><span class="hs-comment">--</span><span>
</span><span id="line-116"></span><span class="hs-comment">-- * the 'nullPtr' is used to represent 'Nothing'</span><span>
</span><span id="line-117"></span><span class="hs-comment">--</span><span>
</span><span id="line-118"></span><span id="local-6989586621679537889"><span id="local-6989586621679537890"><span class="annot"><a href="Foreign.Marshal.Utils.html#maybeNew"><span class="hs-identifier hs-type">maybeNew</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span>      </span><span class="annot"><a href="#local-6989586621679537890"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537889"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-119"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537890"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537889"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-120"></span><span id="maybeNew"><span class="annot"><span class="annottext">maybeNew :: forall a b. (a -&gt; IO (Ptr b)) -&gt; Maybe a -&gt; IO (Ptr b)
</span><a href="Foreign.Marshal.Utils.html#maybeNew"><span class="hs-identifier hs-var hs-var">maybeNew</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Ptr b) -&gt; (a -&gt; IO (Ptr b)) -&gt; Maybe a -&gt; IO (Ptr b)
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr b -&gt; IO (Ptr b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr b
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span class="hs-comment">-- |Converts a @withXXX@ combinator into one marshalling a value wrapped</span><span>
</span><span id="line-123"></span><span class="hs-comment">-- into a 'Maybe', using 'nullPtr' to represent 'Nothing'.</span><span>
</span><span id="line-124"></span><span class="hs-comment">--</span><span>
</span><span id="line-125"></span><span id="local-6989586621679537881"><span id="local-6989586621679537882"><span id="local-6989586621679537883"><span class="annot"><a href="Foreign.Marshal.Utils.html#maybeWith"><span class="hs-identifier hs-type">maybeWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span>      </span><span class="annot"><a href="#local-6989586621679537883"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537882"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537881"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537881"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-126"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537883"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537882"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537881"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537881"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span></span></span></span><span>
</span><span id="line-127"></span><span id="maybeWith"><span class="annot"><span class="annottext">maybeWith :: forall a b c.
(a -&gt; (Ptr b -&gt; IO c) -&gt; IO c)
-&gt; Maybe a -&gt; (Ptr b -&gt; IO c) -&gt; IO c
</span><a href="Foreign.Marshal.Utils.html#maybeWith"><span class="hs-identifier hs-var hs-var">maybeWith</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Ptr b -&gt; IO c) -&gt; IO c)
-&gt; (a -&gt; (Ptr b -&gt; IO c) -&gt; IO c)
-&gt; Maybe a
-&gt; (Ptr b -&gt; IO c)
-&gt; IO c
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Ptr b -&gt; IO c) -&gt; Ptr b -&gt; IO c
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr b
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="hs-comment">-- |Convert a peek combinator into a one returning 'Nothing' if applied to a</span><span>
</span><span id="line-130"></span><span class="hs-comment">-- 'nullPtr'</span><span>
</span><span id="line-131"></span><span class="hs-comment">--</span><span>
</span><span id="line-132"></span><span id="local-6989586621679537876"><span id="local-6989586621679537877"><span class="annot"><a href="Foreign.Marshal.Utils.html#maybePeek"><span class="hs-identifier hs-type">maybePeek</span></a></span><span>                           </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537877"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537876"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537877"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537876"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-133"></span><span id="maybePeek"><span class="annot"><span class="annottext">maybePeek :: forall a b. (Ptr a -&gt; IO b) -&gt; Ptr a -&gt; IO (Maybe b)
</span><a href="Foreign.Marshal.Utils.html#maybePeek"><span class="hs-identifier hs-var hs-var">maybePeek</span></a></span></span><span> </span><span id="local-6989586621679537805"><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537805"><span class="hs-identifier hs-var">peek</span></a></span></span><span> </span><span id="local-6989586621679537804"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537804"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537804"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe b -&gt; IO (Maybe b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe b
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-134"></span><span>                   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679537803"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679537803"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO b
</span><a href="#local-6989586621679537805"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537804"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Maybe b -&gt; IO (Maybe b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; Maybe b
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679537803"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-135"></span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span class="hs-comment">-- marshalling lists of storable objects</span><span>
</span><span id="line-138"></span><span class="hs-comment">-- -------------------------------------</span><span>
</span><span id="line-139"></span><span>
</span><span id="line-140"></span><span class="hs-comment">-- |Replicates a @withXXX@ combinator over a list of objects, yielding a list of</span><span>
</span><span id="line-141"></span><span class="hs-comment">-- marshalled objects</span><span>
</span><span id="line-142"></span><span class="hs-comment">--</span><span>
</span><span id="line-143"></span><span id="local-6989586621679537869"><span id="local-6989586621679537870"><span id="local-6989586621679537871"><span class="annot"><a href="Foreign.Marshal.Utils.html#withMany"><span class="hs-identifier hs-type">withMany</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679537871"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679537870"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537869"><span class="hs-identifier hs-type">res</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537869"><span class="hs-identifier hs-type">res</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- withXXX combinator for one object</span><span>
</span><span id="line-144"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679537871"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span>                       </span><span class="hs-comment">-- storable objects</span><span>
</span><span id="line-145"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679537870"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537869"><span class="hs-identifier hs-type">res</span></a></span><span class="hs-special">)</span><span>              </span><span class="hs-comment">-- action on list of marshalled obj.s</span><span>
</span><span id="line-146"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679537869"><span class="hs-identifier hs-type">res</span></a></span></span></span></span><span>
</span><span id="line-147"></span><span id="withMany"><span class="annot"><span class="annottext">withMany :: forall a b res.
(a -&gt; (b -&gt; res) -&gt; res) -&gt; [a] -&gt; ([b] -&gt; res) -&gt; res
</span><a href="Foreign.Marshal.Utils.html#withMany"><span class="hs-identifier hs-var hs-var">withMany</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; (b -&gt; res) -&gt; res
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span id="local-6989586621679537802"><span class="annot"><span class="annottext">[b] -&gt; res
</span><a href="#local-6989586621679537802"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[b] -&gt; res
</span><a href="#local-6989586621679537802"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-148"></span><span class="annot"><a href="Foreign.Marshal.Utils.html#withMany"><span class="hs-identifier hs-var">withMany</span></a></span><span> </span><span id="local-6989586621679537801"><span class="annot"><span class="annottext">a -&gt; (b -&gt; res) -&gt; res
</span><a href="#local-6989586621679537801"><span class="hs-identifier hs-var">withFoo</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679537800"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679537800"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679537799"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679537799"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679537798"><span class="annot"><span class="annottext">[b] -&gt; res
</span><a href="#local-6989586621679537798"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; (b -&gt; res) -&gt; res
</span><a href="#local-6989586621679537801"><span class="hs-identifier hs-var">withFoo</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679537800"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">((b -&gt; res) -&gt; res) -&gt; (b -&gt; res) -&gt; res
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679537797"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679537797"><span class="hs-identifier hs-var">x'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-149"></span><span>                              </span><span class="annot"><span class="annottext">(a -&gt; (b -&gt; res) -&gt; res) -&gt; [a] -&gt; ([b] -&gt; res) -&gt; res
forall a b res.
(a -&gt; (b -&gt; res) -&gt; res) -&gt; [a] -&gt; ([b] -&gt; res) -&gt; res
</span><a href="Foreign.Marshal.Utils.html#withMany"><span class="hs-identifier hs-var">withMany</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; (b -&gt; res) -&gt; res
</span><a href="#local-6989586621679537801"><span class="hs-identifier hs-var">withFoo</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679537799"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679537796"><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679537796"><span class="hs-identifier hs-var">xs'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[b] -&gt; res
</span><a href="#local-6989586621679537798"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679537797"><span class="hs-identifier hs-var">x'</span></a></span><span class="annot"><span class="annottext">b -&gt; [b] -&gt; [b]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679537796"><span class="hs-identifier hs-var">xs'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span class="hs-comment">-- Haskellish interface to memcpy and memmove</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- ------------------------------------------</span><span>
</span><span id="line-154"></span><span>
</span><span id="line-155"></span><span class="hs-comment">-- |Copies the given number of bytes from the second area (source) into the</span><span>
</span><span id="line-156"></span><span class="hs-comment">-- first (destination); the copied areas may /not/ overlap</span><span>
</span><span id="line-157"></span><span class="hs-comment">--</span><span>
</span><span id="line-158"></span><span id="local-6989586621679537865"><span class="annot"><a href="Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier hs-type">copyBytes</span></a></span><span>
</span><span id="line-159"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537865"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-comment">-- ^ Destination</span><span>
</span><span id="line-160"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537865"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-comment">-- ^ Source</span><span>
</span><span id="line-161"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- ^ Size in bytes</span><span>
</span><span id="line-162"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-163"></span><span id="copyBytes"><span class="annot"><span class="annottext">copyBytes :: forall a. Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier hs-var hs-var">copyBytes</span></a></span></span><span> </span><span id="local-6989586621679537789"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537789"><span class="hs-identifier hs-var">dest</span></a></span></span><span> </span><span id="local-6989586621679537788"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537788"><span class="hs-identifier hs-var">src</span></a></span></span><span> </span><span id="local-6989586621679537787"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537787"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-164"></span><span>  </span><span class="annot"><span class="annottext">Ptr a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr a)
forall a. Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Utils.html#memcpy"><span class="hs-identifier hs-var">memcpy</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537789"><span class="hs-identifier hs-var">dest</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537788"><span class="hs-identifier hs-var">src</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537787"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-165"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span class="hs-comment">-- |Copies the given number of bytes from the second area (source) into the</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- first (destination); the copied areas /may/ overlap</span><span>
</span><span id="line-169"></span><span class="hs-comment">--</span><span>
</span><span id="line-170"></span><span id="local-6989586621679537785"><span class="annot"><a href="Foreign.Marshal.Utils.html#moveBytes"><span class="hs-identifier hs-type">moveBytes</span></a></span><span>
</span><span id="line-171"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537785"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-comment">-- ^ Destination</span><span>
</span><span id="line-172"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537785"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-comment">-- ^ Source</span><span>
</span><span id="line-173"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- ^ Size in bytes</span><span>
</span><span id="line-174"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-175"></span><span id="moveBytes"><span class="annot"><span class="annottext">moveBytes :: forall a. Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="Foreign.Marshal.Utils.html#moveBytes"><span class="hs-identifier hs-var hs-var">moveBytes</span></a></span></span><span> </span><span id="local-6989586621679537780"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537780"><span class="hs-identifier hs-var">dest</span></a></span></span><span> </span><span id="local-6989586621679537779"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537779"><span class="hs-identifier hs-var">src</span></a></span></span><span> </span><span id="local-6989586621679537778"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537778"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-176"></span><span>  </span><span class="annot"><span class="annottext">Ptr a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr a)
forall a. Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Utils.html#memmove"><span class="hs-identifier hs-var">memmove</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537780"><span class="hs-identifier hs-var">dest</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537779"><span class="hs-identifier hs-var">src</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537778"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-178"></span><span>
</span><span id="line-179"></span><span class="hs-comment">-- Filling up memory area with required values</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- -------------------------------------------</span><span>
</span><span id="line-181"></span><span>
</span><span id="line-182"></span><span class="hs-comment">-- |Fill a given number of bytes in memory area with a byte value.</span><span>
</span><span id="line-183"></span><span class="hs-comment">--</span><span>
</span><span id="line-184"></span><span class="hs-comment">-- @since 4.8.0.0</span><span>
</span><span id="line-185"></span><span id="local-6989586621679537858"><span class="annot"><a href="Foreign.Marshal.Utils.html#fillBytes"><span class="hs-identifier hs-type">fillBytes</span></a></span><span>               </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537858"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-186"></span><span id="fillBytes"><span class="annot"><span class="annottext">fillBytes :: forall a. Ptr a -&gt; Word8 -&gt; Int -&gt; IO ()
</span><a href="Foreign.Marshal.Utils.html#fillBytes"><span class="hs-identifier hs-var hs-var">fillBytes</span></a></span></span><span> </span><span id="local-6989586621679537768"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537768"><span class="hs-identifier hs-var">dest</span></a></span></span><span> </span><span id="local-6989586621679537767"><span class="annot"><span class="annottext">Word8
</span><a href="#local-6989586621679537767"><span class="hs-identifier hs-var">char</span></a></span></span><span> </span><span id="local-6989586621679537766"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537766"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-187"></span><span>  </span><span class="annot"><span class="annottext">Ptr a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; CInt -&gt; CSize -&gt; IO (Ptr a)
forall a. Ptr a -&gt; CInt -&gt; CSize -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Utils.html#memset"><span class="hs-identifier hs-var">memset</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679537768"><span class="hs-identifier hs-var">dest</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8 -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Word8
</span><a href="#local-6989586621679537767"><span class="hs-identifier hs-var">char</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537766"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-188"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="hs-comment">-- auxiliary routines</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- -------------------</span><span>
</span><span id="line-192"></span><span>
</span><span id="line-193"></span><span class="hs-comment">-- |Basic C routines needed for memory copying</span><span>
</span><span id="line-194"></span><span class="hs-comment">--</span><span>
</span><span id="line-195"></span><span id="local-6989586621679537862"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;string.h&quot;</span></span><span> </span><span id="memcpy"><span class="annot"><a href="Foreign.Marshal.Utils.html#memcpy"><span class="hs-identifier hs-var">memcpy</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537862"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537862"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537862"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-196"></span><span id="local-6989586621679537764"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;string.h&quot;</span></span><span> </span><span id="memmove"><span class="annot"><a href="Foreign.Marshal.Utils.html#memmove"><span class="hs-identifier hs-var">memmove</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537764"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537764"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537764"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-197"></span><span id="local-6989586621679537855"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;string.h&quot;</span></span><span> </span><span id="memset"><span class="annot"><a href="Foreign.Marshal.Utils.html#memset"><span class="hs-identifier hs-var">memset</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537855"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679537855"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-198"></span></pre></body></html>